package com.lx.timer.java;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * java自带的基于线程池设计的定时任务
 *
 * @author 段誉
 * @create 2019-04-02 14:07
 */
public class TestScheduledExecutorService {
  public static void main(String[] args) {
    ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
    // 参数：1.任务体，2.首次执行的延时时间
    //      3.任务执行间隔，4.间隔时间单位
    service.scheduleAtFixedRate(new Runnable() {
      public void run() {
        System.out.println("task ScheduledExecutorService:" + System.currentTimeMillis());
      }
    }, 0, 3, TimeUnit.SECONDS);
  }
}
